package com.chen.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.dto.ExamPlanDTO;
import com.chen.entity.ExamPlan;
import com.chen.mapper.ExamPlanMapper;
import com.chen.service.ExamPlanService;
import com.chen.vo.ExamPlanVO;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 考试计划服务实现
 */
@Service
public class ExamPlanServiceImpl extends ServiceImpl<ExamPlanMapper, ExamPlan> implements ExamPlanService {

    @Override
    public List<ExamPlanVO> getStudentWillExam(Integer classId, Integer gradeId) {
        if (ObjectUtil.isNotEmpty(classId) && ObjectUtil.isNotEmpty(gradeId)) {
            return baseMapper.getStudentWillExam(classId, gradeId);
        }
        return Collections.emptyList();
    }

    @Override
    public List<ExamPlanVO> getExamPlanList() {
        return baseMapper.getExamPlanList();
    }

    @Override
    public ExamPlanVO getExamPlanById(Integer id) {
        return baseMapper.getExamPlanById(id);
    }

    /**
     * 通过id删除考试计划
     * @param id
     * @return
     */
    @Override
    public Integer delById(Integer id) {
        return baseMapper.deleteById(id);
    }

    /**
     * 添加或编辑考试计划
     * @param dto
     * @return
     */
    @Override
    public Integer saveOrUpdate(ExamPlanDTO dto) {
        ExamPlan examPlan = BeanUtil.toBean(dto, ExamPlan.class);
        if (ObjectUtil.isNotEmpty(examPlan.getId())) {
            return baseMapper.updateById(examPlan);
        }
        return baseMapper.insert(examPlan);
    }

    @Override
    public Integer deleteExpirePlan() {
        return baseMapper.deleteExpirePlan();
    }
}
